package com.zznj.xzjc.activity.findxiansuo;

import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.zznj.xzjc.R;
import com.zznj.xzjc.base.BaseActivity;
import com.zznj.xzjc.bean.index.AnYuKuBaseData;
import com.zznj.xzjc.bean.index.AnYuKuCaseJudgeData;
import com.zznj.xzjc.bean.index.AnYuKuDetaiData;
import com.zznj.xzjc.net.SharedHelper;
import com.zznj.xzjc.net.entity.BaseBean;
import com.zznj.xzjc.net.entity.DictionaryBean;
import com.zznj.xzjc.net.entity.LoginBean;
import com.zznj.xzjc.net.rxjava.HttpMethods;
import com.zznj.xzjc.net.subscribers.ProgressSubscriber;
import com.zznj.xzjc.net.subscribers.SubscriberOnNextListener;
import com.zznj.xzjc.utils.StringUtils;
import com.zznj.xzjc.utils.TimeUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.Unbinder;
import okhttp3.FormBody;

/**
 * 描述：线索发现
 */
public class ActivityFindXianSuoDetailHlwyq extends BaseActivity {
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.info)
    TextView info;
    @BindView(R.id.guanjianci)
    TextView guanjianci;

    Unbinder unbinder;

    @BindView(R.id.content)
    WebView webView;
    @BindView(R.id.btn_choucang)
    ImageView btn_choucang;
    @BindView(R.id.btn_xssl)
    TextView btn_xssl;

    @Override
    protected int getLayoutId() {
        return R.layout.gyss_activity_fxxs_detail_hlwyq_layout;
    }

    private LoginBean user;
    private String id;
    @Override
    public void initView() {
        id = getIntent().getExtras().getString("id");
        user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        setTitle("案源详情");
        init();
        initWebView();
    }

    private String content = "<h5> 当事人信息 </h5>";

    private void initWebView() {
        WebSettings wvSetting = webView.getSettings();
        wvSetting.setJavaScriptEnabled(true);
        wvSetting.setAllowFileAccess(true);
        wvSetting.setBuiltInZoomControls(false);
        wvSetting.setDomStorageEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        webView.setWebChromeClient(new WebChromeClient());
//        webView.loadUrl("file:///android_asset/h5.html");
//        webView.loadUrl("javascript:insertData('"+content+"')");
//        webView.loadUrl(Constant_Url.url + "p/admin_page_client_product_productDetail.html?id=" + productId);
//        webView.addJavascriptInterface(new MyHtmlJsMethod(), "app");
    }

    private void init() {

    }

    private List<DictionaryBean> fromList;

    private AnYuKuBaseData anYuanBaseData;
    private AnYuKuCaseJudgeData judgeData;
    @Override
    protected void initData() {
        SubscriberOnNextListener<BaseBean> onNextListener = baseBean -> {
            if (baseBean.isSuccess()) {
                String data = baseBean.getMessage();
                if (!StringUtils.isEmpty(data)) {
                    AnYuKuDetaiData d = new Gson().fromJson(data,AnYuKuDetaiData.class);
                    anYuanBaseData = new Gson().fromJson(d.getBasicInfo(),AnYuKuBaseData.class);
                    judgeData = new Gson().fromJson(d.getCaseJudge(),AnYuKuCaseJudgeData.class);
                    title.setText(anYuanBaseData.getTitle());
                    info.setText(TimeUtils.getTime(anYuanBaseData.getHappenedTime(),"yyyy-MM-dd")+"     "+anYuanBaseData.getJurisDictionName()+"        "+anYuanBaseData.getSourceName());
                    guanjianci.setText("关键词："+anYuanBaseData.getTag());
//                    webView.loadUrl("javascript:insertData('"+content+"')");
                    webView.loadUrl("javascript:insertData('"+anYuanBaseData.getContent().replace("src=\"","src=\"http://218.28.192.34:9017/pwlp-hubei")+"')");
                }
            }
        };
        FormBody requestBody = new FormBody.Builder()
                .add("id", id)
                .build();
        HttpMethods.getInstance().publicOpinionGet(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);

    }
}
